package soccerBet.project.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.hibernate.Query;
import org.hibernate.Session;

import soccerBet.project.contracts.EquipaContract;
import soccerBet.project.objects.Equipa;
import soccerBet.project.objects.Estatisticas;
import soccerBet.project.objects.InfoPrecos;
import soccerBet.project.utils.HibernateUtil;



public class EstatisticasDAO {
	

	    
		
	
	    
		public  void insertALLToDB(Set<Estatisticas> estatisticas) {
			// TODO Auto-generated method stub

				Session session = HibernateUtil.getSessionFactory().openSession();
		        session.beginTransaction();
		        
		        for(Estatisticas stats : estatisticas){
		        	session.saveOrUpdate(stats);
		        }
		     
		 
		        //Commit the transaction
		        session.getTransaction().commit();
		        
		    	
				session.close();
			
		}

		public List<Estatisticas> getEstatisticasByJogo(int idJogo) {
			// TODO Auto-generated method stub
			
			Session session = HibernateUtil.getSessionFactory().openSession();
			
			List<Estatisticas>  estatisticasList = (List<Estatisticas> )   session.
			createQuery("select e from Estatisticas as e join e.jogo as j where j.idJogo = ?")
			.setInteger(0, idJogo).list();
			
			
			
			session.close();
			
			return estatisticasList;
		}


		
	    
	}